package com.example.rust;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.springframework.stereotype.Component;

import jnr.ffi.LibraryLoader;
import jnr.ffi.Runtime;
import jnr.ffi.Struct;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class RS {
    private String libEntry = "F:\\xmake-demo\\build\\windows\\x64\\release\\libTest.dll";

    @PostConstruct
    public void start(){
        NC nc = LibraryLoader.create(NC.class).load(libEntry);
        
        Runtime rt = Runtime.getRuntime(nc);
        NC.Buffer buf = new NC.Buffer(rt);
        int ret = Struct.size(buf);
        buf.buf.set("hylink2010");
        buf.len.set(10);
        nc.set(buf);
        log.info("Rust Example: " + String.valueOf(ret));
    }

    @PreDestroy
    public void stop(){
        log.info("stop");
    }
}
